const router = require('koa-router')()
const { SucceedMess, ErrMess } = require('../res-message/index')
const { shoplist, getshop, getproduct } = require('../controller/shop')

router.prefix('/api/shop')

// 附近商店
router.get('/hot-list', async (ctx, next) => {
    const list = await shoplist()

    ctx.body = new SucceedMess(list)
})

// 店铺详情
router.get('/:id', async (ctx, next) => {
    const id = ctx.params.id //店铺id
    const shopMess = await getshop(id)

    ctx.body = new SucceedMess(shopMess)
})


// 某个商店商品列表
router.get('/:id/products', async (ctx, next) => {
    const id = ctx.params.id // 店铺id
    const tabs = ctx.request.tab || 'all'
    const products = await getproduct(id, tabs) // 获取数据库商品

    ctx.body = new SucceedMess(products)
})


module.exports = router